# variables for state var state[4] = [0,0,0,0] var new_state[4] = [0,0,0,0] # reset outputs call sound.system(-1) call leds.top(0,0,0) call leds.bottom.left(0,0,0) call leds.bottom.right(0,0,0) call leds.circle(0,0,0,0,0,0,0,0) # subroutine to display the current state sub display_state call leds.circle(0,state[1]*32,0,state[3]*32,0,state[2]*32,0,state[0]*32) onevent buttons when button.center == 1 do if state[1] == 0 then motor.left.target = 0 motor.right.target = 0 new_state[1] = 1 emit pair_run 3 _emit debug_log [0x3, 0x4, 0xd871, 0, 0x1, 0x12, 0xa0a, 0x9] end end when button.forward == 1 do motor.left.target = 200 motor.right.target = 200 new_state[1] = 0 emit pair_run 4 _emit debug_log [0x4, 0x4, 0xd871, 0, 0x10, 0, 0xe0e, 0x12] end call math.copy(state, new_state) callsub display_state onevent prox when prox.ground.delta[0] <= 400 and prox.ground.delta[1] >= 450 do if state[1] == 0 then motor.left.target = 500 motor.right.target = 500 emit pair_run 0 _emit debug_log [0, 0x3, 0x873, 0x9, 0x190, 0x1c2, 0x12, 0x1414] end end when prox.ground.delta[0] >= 450 and prox.ground.delta[1] <= 400 do if state[1] == 0 then motor.left.target = 500 motor.right.target = 0 emit pair_run 1 _emit debug_log [0x1, 0x3, 0x873, 0x6, 0x190, 0x1c2, 0x12, 0x140a] end end when prox.ground.delta[0] >= 450 and prox.ground.delta[1] >= 450 do if state[1] == 0 then motor.left.target = 0 motor.right.target = 500 emit pair_run 2 _emit debug_log [0x2, 0x3, 0x873, 0x5, 0x190, 0x1c2, 0x12, 0xa14] end end when prox.ground.delta[0] <= 400 and prox.ground.delta[1] <= 400 do if state[1] == 0 then motor.left.target = 500 motor.right.target = 150 emit pair_run 5 _emit debug_log [0x5, 0x3, 0x873, 0xa, 0x190, 0x1c2, 0x12, 0x140d] end end